<template>
	<!--运营商主页 月统计  天统计-->
	<view class="community">
		<view class="head_bg">
		</view>
		<view class="big_box" style="margin-top:-180rpx;">
			<view class="count_tab">
				<view :class="{count_tab_inner: istrue == true,is_active: tabIndex == 1}" @tap="tabSelect" :data-id="1" style="margin-left: 145rpx;">日报表</view>
				<view :class="{count_tab_inner: istrue == true,is_active: tabIndex == 2}" @tap="tabSelect" :data-id="2" style="margin-right: 145rpx;">月报表</view>
			</view>
			<view v-if="tabIndex == 1">
				<view class="operating_box" v-for="(info,index) in list" :key="index" style="margin-top: 45rpx;" >
					<view class="count_title_box">
						<text class="count_title">{{info.statistics_time}}</text>
						<view class="count_right">利润
							<view><text class="count_right_blod" style="margin-right: 10rpx;">{{info.profit}}</text>元
							</view>
						</view>
					</view>
					<view class="count_inner">
						<view class="count_line">
							<view class="count_line_left">收入： </view>
							<view class="count_line_right">+{{info.order_income}}元</view>
						</view>
						<view class="count_line">
							<view class="count_line_left">套餐： </view>
							<view class="count_line_right"> +{{info.set_meal_income}}元</view>
						</view>
						<view class="count_line">
							<view class="count_line_left">电费： </view>
							<view class="count_line_right"> -{{info.order_electricity_fees}}元</view>
						</view>
						<view class="count_line">
							<view class="count_line_left">代理： </view>
							<view class="count_line_right"> -{{info.agent_share}}元</view>
						</view>
						<view class="count_line">
							<view class="count_line_left">物业：</view>
							<view class="count_line_right"> -{{info.property_sharing}}元</view>
						</view>
						<view class="count_line">
							<view class="count_line_left">平台： </view>
							<view class="count_line_right"> -{{info.platform_sharing}}元</view>
						</view>
					</view>
					<view class="count_bottom">
						<view class="count_bottom_inner">充电次数：
						<text class="count_bottom_inner_1"></text>
						<text class="count_bottom_inner_2">{{info.order_num}}</text>
						单次均价：
						<text class="count_bottom_inner_1">￥</text>
						<text  class="count_bottom_inner_2" style="margin-right: 0;">{{info.pv_amount}}</text></view>
					</view>
				</view>
				<view style="height:100rpx;"></view>
				<view v-if="list.length==0" class="margin-top-lg text-center">
					<image src='../../common/img/no_data.png' style="width:275rpx;height:312rpx;"></image>
				</view>
				<view v-if="list.length>0" class="text-black text-df text-center bg-white padding-sm padding-left-lg be-gray">
					{{loadingTxt}} 共({{list.length}}条记录)
				</view>
			</view>
			<view v-if="tabIndex == 2">
				<view class="operating_box" v-for="(info,index) in list" :key="index" style="margin-top: 45rpx;" >
					<view class="count_title_box">
						<text class="count_title">{{info.statistics_month}}</text>
						<view class="count_right">利润
							<view><text class="count_right_blod" style="margin-right: 10rpx;">{{info.profit}}</text>元
							</view>
						</view>
					</view>
					<view class="count_inner">
						<view class="count_line">
							<view class="count_line_left">收入： </view>
							<view class="count_line_right">+{{info.order_income}}元</view>
						</view>
						<view class="count_line">
							<view class="count_line_left">套餐： </view>
							<view class="count_line_right"> +{{info.set_meal_income}}元</view>
						</view>
						<view class="count_line">
							<view class="count_line_left">电费： </view>
							<view class="count_line_right"> -{{info.order_electricity_fees}}元</view>
						</view>
						<view class="count_line">
							<view class="count_line_left">代理： </view>
							<view class="count_line_right"> -{{info.agent_share}}元</view>
						</view>
						<view class="count_line">
							<view class="count_line_left">物业：</view>
							<view class="count_line_right"> -{{info.property_sharing}}元</view>
						</view>
						<view class="count_line">
							<view class="count_line_left">平台： </view>
							<view class="count_line_right"> -{{info.platform_sharing}}元</view>
						</view>
					</view>
					<view class="count_bottom">
						<view class="count_bottom_inner">充电次数：
						<text class="count_bottom_inner_1"></text>
						<text class="count_bottom_inner_2">{{info.order_num}}</text>
						单次均价：
						<text class="count_bottom_inner_1">￥</text>
						<text  class="count_bottom_inner_2" style="margin-right: 0;">{{info.pv_amount}}</text></view>
					</view>
				</view>
				<view style="height:100rpx;"></view>
				<view v-if="list.length==0" class="margin-top-lg text-center">
					<image src='../../common/img/no_data.png' style="width:275rpx;height:312rpx;"></image>
				</view>
				<view v-if="list.length>0" class="text-black text-df text-center bg-white padding-sm padding-left-lg be-gray">
					{{loadingTxt}} 共({{list.length}}条记录)
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	let page=1,timer=null
	export default {
		data() {
			return {
				info:'',
				tabIndex: 1,
				istrue: true,
				list:[],
				loadingTxt:'加载更多',
			}
		},
		onShow() {
			page=1;
			this.gatlist();
		},
		methods: {
			tabSelect(e) {
				page=1;
				this.loadingTxt="加载更多"
				this.tabIndex = e.currentTarget.dataset.id;
				this.gatlist();
			},
			gatlist(){
				let that=this;
				let url;
				if(this.tabIndex==1){
					url="profit/v1/day";
				}else if(this.tabIndex==2){
					url="profit/v1/month";
				}
				that.http.tokenreq({
					url:url,
					data:{"pageindex":page}
				}).then((res) => {
					console.log("res="+JSON.stringify(res));
					let e=res.data;
					if(e.code==0 && e.success){
						let list=e.rows;
						console.log("list="+JSON.stringify(list));
						that.list=list;
						page++;
					}else{
						uni.showModal({
							content:e.message,
							showCancel:false,
						})
					}
				})
			},
			getmorelist(){
				this.loadingTxt='加载中'
				let that=this;
				let url;
				if(this.tabIndex==1){
					url="profit/v1/day";
				}else if(this.tabIndex==2){
					url="profit/v1/month";
				}
				that.http.tokenreq({
					url:url,
					data:{"pageindex":page}
				}).then((res) => {
					console.log("res="+JSON.stringify(res));
					let e=res.data;
					if(e.code==0 && e.success){
						if(e.rows.length==0){
							that.loadingTxt="已经加载全部";
							return;
						}
						that.list=that.list.concat(e.rows);
						page++;
					}else{
						uni.showModal({
							content:e.message,
							showCancel:false,
						})
					}
				})
			},
			onReachBottom() {
				//阻止重复加载
				if(timer !== null){
					clearTimeout(timer)
				}
				timer=setTimeout(()=>this.getmorelist(),500)
			},
		}
	}
</script>
<style>
	.ele_title_inner{
		color: #FFFFFF;
		font-size:36rpx;
	}
</style>